package com.onairm.baselibrary.net;

import android.util.Log;

import com.onairm.baselibrary.Init;
import com.onairm.baselibrary.utils.BaseParamsUtils;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by apple on 17/11/2.
 */

public class ResAndReqInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request oldRequest = chain.request();
        BaseParamsUtils.BaseParams baseParams = BaseParamsUtils.getInstance().getBaseParams();
        HttpUrl build = oldRequest.url().newBuilder()
                .addEncodedQueryParameter("ty", baseParams.getTy())
                .addEncodedQueryParameter("v", baseParams.getV())
                .addEncodedQueryParameter("dk", baseParams.getDk())
                .addEncodedQueryParameter("tn", baseParams.getToken())
                .addEncodedQueryParameter("userId", baseParams.getUserId())
                .build();
        Request newRequest = oldRequest.newBuilder().url(build).build();
        return chain.proceed(newRequest);
    }
}
